﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.NBL.DBEntities;
using SzCourt.Logic.BLL;

namespace SzCourt.WebSite.manager
{
    public partial class lianshenheview : System.Web.UI.Page
    {
        private string _ID = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            if (!this.IsPostBack)
            {
                getInfo();
            }
        }

        private void getInfo()
        {
            this._ID = string.IsNullOrEmpty(Request.QueryString["id"]) ? "" : Request.QueryString["id"];

            pPreCaseInfo param = new pPreCaseInfo();
            param.PreCaseInfoID = int.Parse(this._ID);
            PreCase bll = new PreCase();
            PreCassCollection result = (PreCassCollection)bll.GetPreCaseInfo(param);

            if (result != null)
            {
                this.hdnPreCaseInfoID.Value = result.PreCaseInfo.PreCaseInfoID.ToString();
                this.tdPreCaseSerial.InnerHtml = result.PreCaseInfo.PreCaseSerial;
                this.tdEmail.InnerHtml = result.PreCaseInfo.Email;
                this.tdPhone.InnerHtml = result.PreCaseInfo.Phone;
                switch (result.PreCaseInfo.PreCaseType)
                {
                    case 1:
                        this.tdPreCaseType.InnerHtml = "民事案件";
                        break;
                    case 2:
                        this.tdPreCaseType.InnerHtml = "商事案件";
                        break;
                    default:
                        this.tdPreCaseType.InnerHtml = "执行案件";
                        break;
                }
                this.tdHandleStatus.InnerHtml = result.PreCaseInfo.Audited == 1 ? "已处理" : result.PreCaseInfo.HandleStatus == 0 ? "未处理" : "已处理";
                this.tdAddDateTime.InnerHtml = result.PreCaseInfo.AddDateTime.ToString();
                this.tdAudited.InnerHtml = result.PreCaseInfo.Audited == 1 ? "审核通过" : (result.PreCaseInfo.Audited == 2 ? "审核不通过" : "未审核");
                this.tdStartingMark.InnerHtml = result.PreCaseInfo.StartingMark.HasValue ? result.PreCaseInfo.StartingMark.ToString() : "";
                this.tdCauseOfAction.InnerHtml = result.PreCaseInfo.CauseOfAction;
                this.tdReplyContent.Value = result.PreCaseInfo.ReplyContent;

                //原告
                this.Repeater1.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 1 && a.PartiesType == 0).ToList();
                this.Repeater1.DataBind();
                this.Repeater2.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 2 && a.PartiesType == 0).ToList();
                this.Repeater2.DataBind();
                this.Repeater3.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 3 && a.PartiesType == 0).ToList();
                this.Repeater3.DataBind();

                //被告
                this.Repeater4.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 1 && a.PartiesType == 1).ToList();
                this.Repeater4.DataBind();
                this.Repeater5.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 2 && a.PartiesType == 1).ToList();
                this.Repeater5.DataBind();
                this.Repeater6.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 3 && a.PartiesType == 1).ToList();
                this.Repeater6.DataBind();

                //证据文件
                if (result.PreCaseFile != null && result.PreCaseFile.Count() > 0)
                {
                    this.rptFile.Visible = true;
                    this.rptFile.DataSource = result.PreCaseFile;
                    this.rptFile.DataBind();
                }

            }
        }

        //审核通过按钮事件
        protected void Button1_Click(object sender, EventArgs e)
        {
            pPreCaseInfo param = new pPreCaseInfo();
            param.PreCaseInfoID = int.Parse(this.hdnPreCaseInfoID.Value);
            param.ReplyContent = this.tdReplyContent.Value;

            PreCase bll = new PreCase();
            bool result = (bool)bll.AuditPreCase(param);

            if (result)
            {
                getInfo();
                this.spMessage.InnerHtml = "审核成功！";
            }
            else
            {
                this.spMessage.InnerHtml = "审核失败！";
            }
        }

        //审核通过按钮事件
        protected void Button2_Click(object sender, EventArgs e)
        {
            pPreCaseInfo param = new pPreCaseInfo();
            param.PreCaseInfoID = int.Parse(this.hdnPreCaseInfoID.Value);
            param.ReplyContent = this.tdReplyContent.Value;

            PreCase bll = new PreCase();
            bool result = (bool)bll.UnAuditPreCase(param);

            if (result)
            {
                getInfo();
                this.spMessage.InnerHtml = "审核成功！";
            }
            else
            {
                this.spMessage.InnerHtml = "审核失败！";
            }
        }
    }
}